const express = require("express");
let router = express.Router();
const path = require("path");
// const fs = require("fs");
const bodyParser = require("body-parser");
const newsModel = require("../modules/newsModel.js");
router.use(bodyParser.json())
router.get("/addnews", (req, res) => {
    // 添加新闻页面 
    res.sendFile(path.join(__dirname, "../views/addnews.html"));
})
router.post("/adddata", async (req, res) => {
    // 接收post数据；
    let { title, content } = req.body;
    // console.log(title, content);
    console.log(title, content);
    try {
        await newsModel.create({ title, content })
    } catch (err) {
        res.send("添加失败", err)
    }
})

module.exports = router;